package io.eyer.nio.core.support;

import io.eyer.nio.core.codec.Codec;
import io.eyer.nio.core.event.Connector;
import io.eyer.nio.core.session.SessionHandler;

/**
 * Created by Administrator on 2015/8/28.
 */
public class NioConfig {

    private static Codec codec;
    private static Handler handler;
    private static SessionHandler sessionHandler;
    private static Connector connector;

    public static void registered(Codec codec) {
        NioConfig.codec = codec;
    }

    public static void registered(Handler handler) {
        NioConfig.handler = handler;
    }

    public static void registered(SessionHandler sessionHandler) {
        NioConfig.sessionHandler = sessionHandler;
    }

    public static void registered(Connector connector){ if(!connector.isStarted()){connector.start();}NioConfig.connector = connector;}

    public static Codec getCodec() {
        if (codec == null)
            throw new NullPointerException("codec is null. please invoke NioConfig.registered(Codec codec)");
        return codec;
    }

    public static Handler getHandler() {
        if (handler == null)
            throw new NullPointerException("handler is null. please invoke NioConfig.registered(Dandler handler)");
        return handler;
    }



    public static Connector getConnector(){
        if (handler == null)
            throw new NullPointerException("Connector is null. please invoke NioConfig.registered(Connector connector)");
            return connector;
    }


    public static SessionHandler getSessionHandler() {
        return sessionHandler;
    }

    public static void initSessionHandler() {
        NioConfig.sessionHandler = new SessionHandler();
    }
}
